package com.hzit.search.config;

import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import co.elastic.clients.transport.rest_client.RestClientTransport;
import lombok.Data;
import org.apache.http.HttpHost;

import org.elasticsearch.client.RestClient;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */
@ConfigurationProperties(prefix = "elasticsearch")
@Data
@Configuration
public class ElasticSearchConfig {
	private String host;
	private int port;
	@Bean
	public ElasticsearchClient elasticsearchClient(){
		RestClient restClient = RestClient.builder(
				new HttpHost(host, port)).build();
		ElasticsearchTransport transport = new RestClientTransport(
				restClient, new JacksonJsonpMapper());
		ElasticsearchClient client = new ElasticsearchClient(transport);
		return client;
	}
}
